<template>
  <div class="dashboard-index">
    <panel-group :workerStatics="workerStatics"></panel-group>

    <el-row style="background: #fff; padding: 16px 16px 0">
      <line-chart :chart-data="lineChartData" />
    </el-row>

    <el-row :gutter="30">
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card shadow="hover" class="chart-wrapper">
          <div slot="header" class="clearfix">
            <span>用工单位派遣情况</span>
          </div>
          <raddar-chart :tenantWaitSends="tenantWaitSends" />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card shadow="hover" class="chart-wrapper">
          <div slot="header" class="clearfix">
            <span>工人状态分布</span>
          </div>
          <pie-chart :pieData="pieData" />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card shadow="hover" class="chart-wrapper">
          <div slot="header" class="clearfix">
            <span>最近一周收入情况</span>
          </div>
          <bar-chart />
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="30">
      <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 12 }">
        <el-card shadow="hover" class="chart-wrapper">
          <div slot="header" class="clearfix">
            <span>最新动态</span>
          </div>
          <div class="notice-list-card">
            <notice-list :noticeList="noticeList" />
          </div>
        </el-card>
      </el-col>
      <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 12 }">
        <el-card shadow="hover" class="chart-wrapper">
          <div slot="header" class="clearfix">
            <span>合同提醒</span>
          </div>
          <div class="contract-list-card">
            <contract-list :contractList="contractList" />
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getExternalLink } from '@common/api/staff';
import { getStatusStatistics } from '@common/api/worker';
import { getContractList } from '@common/api/contract';
import { getTenantList } from '@common/api/tenant';
import { getNoticeList } from '@common/api/user';
import PanelGroup from './components/PanelGroup.vue';
import NoticeList from './components/NoticeList.vue';

import LineChart from './components/LineChart';
import RaddarChart from './components/RaddarChart';
import PieChart from './components/PieChart';
import BarChart from './components/BarChart';
import ContractList from './components/ContractList.vue';

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145],
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130],
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130],
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130],
  },
};

export default {
  components: {
    PanelGroup,
    NoticeList,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    ContractList,
  },
  data() {
    return {
      iframeSrc: '',
      contentLoading: true,
      calendarValue: new Date(),
      workerStatics: {
        noSign: 0,
        waitSend: 0,
        send: 0,
        tenantInit: 0,
        tenantAll: 0,
      },
      noticeList: [],
      contractList: [],

      lineChartData: lineChartData.newVisitis,
      pieData: {
        '': 0,
        ALL: 0,
        INIT: 0,
        QUIT_JOB: 0,
        SEND: 0,
      },
      tenantWaitSends: [],
    };
  },
  created() {
    this.getPanelData();
    getExternalLink({
      Module: '',
      ModuleId: '',
      MenuStatus: 'DISABLE',
    }).then(data => {
      this.iframeSrc = data.data.ConsoleUrl;
      this.contentLoading = false;
    });

    getTenantList({
      status: 'INIT',
      offset: 0,
      limit: 1000000,
    }).then(res => {
      console.log(res, '00000000');
      this.workerStatics.tenantInit = res?.data?.tenants?.length || 0;
    });
    getTenantList({
      status: 'ALL',
      offset: 0,
      limit: 1000000,
    }).then(res => {
      this.workerStatics.tenantAll = res?.data?.tenants?.length || 0;
    });
    this.fetchNoticeList();
    this.getContractList();
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type];
    },
    async fetchNoticeList() {
      getNoticeList().then(res => {
        this.noticeList = res?.data || [];
      });
    },
    async getPanelData() {
      getStatusStatistics().then(res => {
        const { currentSend, tenantWaitSends } = res?.data || {};
        this.pieData = currentSend;
        this.tenantWaitSends = tenantWaitSends;
        this.workerStatics.noSign = currentSend[''] || 0;
        this.workerStatics.waitSend = currentSend.ALL || 0;
        this.workerStatics.send = currentSend.SEND || 0;
      });
      // try {
      // const { data } = await getStaticsData({
      //   statusList: ['', 'ALL', 'SEND'], // WAIT_SEND:待派遣，SEND：已派遣，''：未发起合同
      // });
      // if (data?.length) {
      //   // eslint-disable-next-line prefer-destructuring
      //   this.workerStatics.noSign = data[0];
      //   // eslint-disable-next-line prefer-destructuring
      //   this.workerStatics.waitSend = data[1];
      //   // eslint-disable-next-line prefer-destructuring
      //   this.workerStatics.send = data[2];
      // }
      // } catch (error) {
      //   console.log('工人统计信息获取失败', error);
      // }
    },
    async getContractList() {
      getContractList({
        limit: 6,
        offset: 0,
      }).then(res => {
        this.contractList = res.data.contracts;
      });
    },
  },
};
</script>


<style lang="scss">
.el-card {
  margin-top: 20px;
  .el-card__header {
    padding: 12px 20px;
  }
}

.contract-list-card,
.notice-list-card {
  overflow-y: auto;
  overflow-x: hidden;
  height: 420px;
}

ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}
.dashboard-index {
  padding: 20px 30px;
  background-color: #f0f2f5;
  .content-list {
    display: flex;
    .calendar,
    .runtime-notice {
      width: 50%;
    }
    .calendar {
      margin-right: 20px;
    }
    .el-card.is-always-shadow {
      box-shadow: 0 2px 6px 0 rgb(0 0 0 / 1%);
    }
  }
}
</style>
